// 下方 锚点 - hover 时 显示
export function anchorPointVisible (item, visible, isInAnchorPoint) {
    const group = item.getContainer()

    if (isInAnchorPoint) {
        group.find(g => {
            if (g.cfg.name === 'anchorPoint' && g.attrs.isInAnchorPoint) {
                g.attr('opacity', +visible)
                g.attr('cursor', visible ? 'default' : 'crosshair')
            }
        })
    } else {
        group.find(g => {
            if (g.cfg.name === 'anchorPoint') {
                g.attr('opacity', +visible)
            }
        })
    }
}

// 锚点 - 热区
export function anchorPointAreaVisible (item, visible) {
    const group = item.getContainer()
    group.find(g => {
        if (g.cfg.name === 'anchorPointArea' && g.attrs.isInAnchorPoint) {
            const isInAnchorPoint = g.cfg.y === 0

            g.attr('opacity', visible ? 0.3 : 0)
            g.attr('cursor', visible ? 'default' : (isInAnchorPoint ? 'move' : 'crosshair'))
        }
    })
}

// 上方 锚点 - mode 为 addEdge 时 样式
export function inAnchorPointActive (graph, visible = true) {
    const findNode = graph.findAll('node', node => {
        return node.get('model').type === 'customNode'
    })

    if (Array.isArray(findNode)) {
        findNode.forEach(item => {
            anchorPointVisible(item, visible, true)
            anchorPointAreaVisible(item, visible)
        })
    }
}
